Array move Method
Syntax
Arguments
- fromNumeric
The current position of the element being moved.
- toNumeric
The new position of the element being moved.
- elemsNumeric
The number of elements to move. Default value is 1.
Description
Move an array entry from one position to another.
Discussion
The <array>.move() method moves an element in a single dimensional array From the specified position specified To the specified position.
Example
Consider an array defined as follows:
dim A[5] as C A[1] = "Orange" A[2] = "Banana" A[3] = "Apple" A[4] = "Pineapple" A[5] = "Mango"
Let's assume we want to move the entry "Pineapple" between "Orange" and "Banana". This is done by calling the <array>.move() method as follows:
A.move(4,2) ? A = [1] = "Orange" [2] = "Pineapple" [3] = "Banana" [4] = "Apple" [5] = "Mango"
Using <array>.move() with Property Arrays
Assume you have a property array.
dim px[2] as P px[1].NAME = "sam" px[1].city = "boston" px[2].NAME = "colin" px[2].city = "ithaca"
The array "looks" like this:
Element | NAME | city |
---|---|---|
px[1] | sam | boston |
px[2] | colin | ithica |
To move element 2 into element 1, you issue the command:
px.move(2,1)
Now, the array "looks" like this:
Element | NAME | city |
---|---|---|
px[1] | colin | ithica |
px[2] | sam | boston |
Moving Multiple Entries
The third parameter can be used to specify the number of elements to move. For example:
dim A[10] as C A[1] = "Orange" A[2] = "Banana" A[3] = "Apple" A[4] = "Pineapple" A[5] = "Mango" ? A = [1] = "Orange" [2] = "Banana" [3] = "Apple" [4] = "Pineapple" [5] = "Mango" [6] = "" [7] = "" [8] = "" [9] = "" [10] = "" A.move(2,7,3) ? A = [1] = "Orange" [2] = "Mango" [3] = "" [4] = "" [5] = "Banana" [6] = "Apple" [7] = "Pineapple" [8] = "" [9] = ""